package cn.edu.zut.hhr.handler;

import cn.edu.zut.hhr.enums.IddentityEnum;
import org.apache.ibatis.type.EnumTypeHandler;
import org.apache.ibatis.type.JdbcType;

import java.sql.CallableStatement;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;

public class ShopEnumHandler extends EnumTypeHandler<IddentityEnum> {

    public ShopEnumHandler(Class<IddentityEnum> type) {
        super(type);
    }

    @Override
    public void setNonNullParameter(PreparedStatement ps, int i, IddentityEnum parameter, JdbcType jdbcType) throws SQLException {
        ps.setBoolean(i,parameter.isCustomer());
    }

    @Override
    public IddentityEnum getNullableResult(ResultSet rs, String columnName) throws SQLException {
        Boolean b = rs.getBoolean(columnName);
        return IddentityEnum.getByBoolean(b);
    }

    @Override
    public IddentityEnum getNullableResult(ResultSet rs, int columnIndex) throws SQLException {
        Boolean b = rs.getBoolean(columnIndex);
        return IddentityEnum.getByBoolean(b);
    }

    @Override
    public IddentityEnum getNullableResult(CallableStatement cs, int columnIndex) throws SQLException {
        Boolean b = cs.getBoolean(columnIndex);
        return IddentityEnum.getByBoolean(b);
    }
}
